/**
 * 
 */
package br.com.ufrn.aipetro.ga.controller.device;

import java.util.List;

import br.com.ufrn.aipetro.ga.domain.entity.device.OperationStatus;
import br.com.ufrn.aipetro.ga.domain.entity.device.Protocol;
import br.com.ufrn.aipetro.ga.domain.entity.device.sensor.sensorlevel.SensorLevel;
import br.com.ufrn.aipetro.ga.domain.entity.mesh.Mesh;
import br.com.ufrn.aipetro.ga.domain.entity.plant.Plant;
import br.com.ufrn.aipetro.ga.domain.entity.unit.Unit;
import br.com.ufrn.aipetro.ga.persist.interfaces.DaoFactory;

/**
 * @author Lucas
 *
 */
public class SensorLevelController extends DeviceController<SensorLevel> {
	
	DaoFactory daoFactory;
	
	public SensorLevelController(DaoFactory factory) {
		this.daoFactory = factory;
		setModel(new SensorLevel());
	}
	
	public void changeDeviceId(String deviceId) {
		getModel().setDeviceId(deviceId);
	}
	
	public void changeManufacturer(String manufacturer) {
		getModel().setManufacturer(manufacturer);
	}
	
	public void changeMesh(Mesh mesh) {
		getModel().setMesh(mesh);
	}
	
	public void changeModel(String model) {
		getModel().setModel(model);
	}
	
	public void changeOperationStatus(OperationStatus operationStatus) {
		getModel().setOperationStatus(operationStatus);
	}
	
	public void changeProtocol(Protocol protocol) {
		getModel().setProtocol(protocol);
	}
	
	public void changeSerialNumber(String serialNumber) {
		getModel().setSerialNumber(serialNumber);
	}
	
	public void changeTag(String tag) {
		getModel().setTag(tag);
	}
	
	public void changeName(String name) {
		getModel().setName(name);
	}

	public void changeOperationTemperature(float operationtemperature) {
		getModel().setOperationTemperature(operationtemperature);
	}
	
	public void changeRange(float range) {
		getModel().setRanged(range);
	}

	public void changeSampleRate(float sampleRate) {
		getModel().setSampleRate(sampleRate);
	}
	
	public void changeLevel(float level) {
		getModel().setLevel(level);
	}

	public void changeLengthMax(float lengthmax) {
		getModel().setLengthMax(lengthmax);
	}
	
	
	public void persistInsert() {
		daoFactory.beginTransaction();
		daoFactory.createSensorLevelDao().insert(getModel());
		daoFactory.commitTransaction();
	}
	
	public void persistUpdate() {
		daoFactory.beginTransaction();
		daoFactory.createSensorLevelDao().update(getModel());
		daoFactory.commitTransaction();
	}
	
	public List<SensorLevel> persistSearchAll() {
		daoFactory.beginTransaction();
		List<SensorLevel> listMesh = daoFactory.createSensorLevelDao().searchAll();
		daoFactory.commitTransaction();
		return listMesh;
	}
	
	public List<Unit> persistSearchAllUnit() {
		daoFactory.beginTransaction();
		List<Unit> listUnit = daoFactory.createUnitDao().searchAll();
		daoFactory.commitTransaction();
		return listUnit;
	}
	
	public List<Plant> persistSearchPlantByUnit(Unit unit) {
		daoFactory.beginTransaction();
		List<Plant> listPlant = daoFactory.createPlantDao().searchByUnit(unit);
		daoFactory.commitTransaction();
		return listPlant;
	}
	
	public List<OperationStatus> persistSearchAllOperationStatus() {
		daoFactory.beginTransaction();
		List<OperationStatus> listOperationStatus = daoFactory.createOperationStatusDao().searchAll();
		daoFactory.commitTransaction();
		return listOperationStatus;
	}
	
	public List<Mesh> persistSearchMeshByPlant(Plant plant) {
		daoFactory.beginTransaction();
		List<Mesh> listMesh = daoFactory.createMeshDao().searchByPlant(plant);
		daoFactory.commitTransaction();
		return listMesh;
	}
	
	public List<Protocol> persistSearchAllProtocol() {
		daoFactory.beginTransaction();
		List<Protocol> listProtocol = daoFactory.createProtocolDao().searchAll();
		daoFactory.commitTransaction();
		return listProtocol;
	}

}
